package com.wlx.gateway.config;

import com.wlx.gateway.handler.SendCodeHandler;
import com.wlx.gateway.handler.ValidateCodeHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;

/**
 * 路由配置信息
 *
 * @author wlx
 */
@Configuration
public class RouterFunctionConfiguration {
    @Autowired
    private ValidateCodeHandler validateCodeHandler;

    @Autowired
    private SendCodeHandler sendCodeHandler;

    @SuppressWarnings("rawtypes")
    @Bean
    public RouterFunction routerFunction() {
        return RouterFunctions.route(
                RequestPredicates.GET("/code").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)),
                validateCodeHandler)
                .andRoute(
                RequestPredicates.GET("/send").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)),
                sendCodeHandler).and(RouterFunctions.route(RequestPredicates.GET("/send?type={type}&receiver={receiver}&appId={appId}"), sendCodeHandler))
                ;
    }
}
